import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';

const FZF = () => import('@/views/common/lb/FZF.vue');
const site = () => import('@/components/header/site.vue');
const local = () => import('@/views/local.vue');
const fri = () => import('@/views/fri.vue');
const integral = () => import('@/views/integral.vue');
const gouwuche = () => import('@/views/Shop.vue');
const integralx = () => import('@/views/integralx.vue');

const shop = () => import('@/views/shopx.vue');
const order = () => import('@/views/order.vue');
const zhifuwancheng = () => import('@/views/zhifuwancheng.vue');
Vue.use(VueRouter);

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },

  {
    path: '/site',
    name: 'site',
    component: site,
  },
  {
    path: '/local',
    name: 'local',
    component: local,
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/components/login/login.vue'),
  },
  {
    path: '/phlogin',
    name: 'phlogin',
    component: () => import('@/components/login/phLogin.vue'),
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/components/login/register.vue'),
  },
  {
    //忘记密码
    path: '/fgpsd',
    name: 'fgpsd',
    component: () => import('@/components/login/fogetPsd.vue'),
  },
  {
    //优先保障
    path: '/fri',
    name: 'fri',
    component: fri,
  },
  {
    path: '/integralx',
    name: 'integralx',
    component: integralx,
  },
  {
    path: '/integral',
    name: 'integral',
    component: integral,
  },
  {
    path: '/order',
    name: 'order',
    component: order,
  },
  {
    path: '/shop',
    name: 'shop',
    component: shop,
  },
  {
    path: '/gouwuche',
    name: 'gouwuche',
    component: gouwuche,
  },
  { path: '/zhifuwancheng', name: 'zhifuwancheng', component: zhifuwancheng },
  {
    path: '/grzx',
    name: 'grzx',
    component: () => import('@/components/grzx/grzx.vue'),
    redirect: '/grzx/wdzh',
    children: [
      {
        path: '/grzx/wdzh',
        name: 'gz-wdzh',
        component: () => import('@/components/grzx/wdzh.vue'),
      },
      {
        path: '/grzx/wddd',
        name: 'gz-wddd',
        component: () => import('@/components/grzx/wddd.vue'),
      },
      {
        path: '/grzx/wdjf',
        name: 'gz-wdjf',
        component: () => import('@/components/grzx/wdjf.vue'),
      },
      {
        path: '/grzx/jfdd',
        name: 'gz-jfdd',
        component: () => import('@/components/grzx/jfdd.vue'),
      },
      {
        path: '/grzx/wdqb',
        name: 'gz-wdqb',
        component: () => import('@/components/grzx/wdqb.vue'),
      },
      {
        path: '/grzx/grzl',
        name: 'gz-grzl',
        component: () => import('@/components/grzx/grzl.vue'),
      },
      {
        path: '/grzx/dzgl',
        name: 'gz-dzgl',
        component: () => import('@/components/grzx/dzgl.vue'),
      },
      {
        path: '/grzx/wdsc',
        name: 'gz-wdsc',
        component: () => import('@/components/grzx/wdsc.vue'),
      },
      {
        path: '/grzx/zjll',
        name: 'gz-zjll',
        component: () => import('@/components/grzx/zjll.vue'),
      },
      {
        path: '/grzx/xgmm',
        name: 'gz-xgmm',
        component: () => import('@/components/grzx/xgmm.vue'),
      },
      {
        path: '/grzx/wdxx',
        name: 'gz-wdxx',
        component: () => import('@/components/grzx/wdxx.vue'),
      },
      {
        path: '/grzx/yjfk',
        name: 'gz-yjfk',
        component: () => import('@/components/grzx/yjfk.vue'),
      },
    ],
  },
  {
    path: '*',
    name: 'fzf',
    component: FZF,
  },
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes,
});
router.beforeEach((to, from, next) => {
  let user = localStorage.getItem('userId') || 'error';
  //判断是否登录或者是否跳转到登录
  if (!user) {
    next('/login');
  } else {
    next();
  }
});
export default router;
